1. Field of the Invention
The present invention relates to techniques for improving performance within computer systems. More specifically, the present invention relates to a method and apparatus for enabling optimistic program execution.
2. Related Art
Several software and hardware mechanisms exist that can initiate a control transfer of execution to a pre-determined address in the event of an error or a failure during execution of a bounded-execution block. Examples of such mechanisms include try-catch blocks in languages including C++ and JAVA, the C library's setjmp-longjmp functions, and transactional-execution blocks in systems that support transactional memory. (JAVA is a registered trademark of Oracle Corporation).
These bounded-execution blocks contain a primary path, which is the preferable path or the optimal path, to be taken when executing the bounded-execution block. If the execution of the primary path fails, execution of the bounded-execution block restarts at the entrance of a secondary path. This secondary path can perform actions such as executing a copy of the instructions on the primary path using a different contention-handling mechanism (e.g., using locks instead of using transactional memory mechanisms), or performing a remedial action such as reporting an error.
The primary path is generally the optimistic path. If the execution of code on the primary path succeeds, then the overall execution time of the program will be reduced. However, conditions within the computer system can cause the primary path to constantly fail or to be less optimal than the secondary path. If the bounded-execution block is executed many times (e.g., within a for loop), it is inefficient and costly to repeatedly execute the code on the primary path when the code is likely to fail or is less optimal than the code in the secondary path.
Because of this risk, programmers and compilers use these techniques less aggressively than possible. In other words, they produce less-than-optimal code in the common case in order to avoid significant performance problems in unusual situations. Hence, what is needed is a method and an apparatus for enabling optimistic program execution.